package com.ruoyi.web.controller.myuser;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MyUser;
import com.ruoyi.system.service.IMyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户信息Controller
 * 
 * @author 777
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/myuser/myuser")
public class MyUserController extends BaseController
{
    @Autowired
    private IMyUserService myUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('myuser:myuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyUser myUser)
    {
        startPage();
        List<MyUser> list = myUserService.selectMyUserList(myUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('myuser:myuser:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyUser myUser)
    {
        List<MyUser> list = myUserService.selectMyUserList(myUser);
        ExcelUtil<MyUser> util = new ExcelUtil<MyUser>(MyUser.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('myuser:myuser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(myUserService.selectMyUserByUserId(userId));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('myuser:myuser:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyUser myUser)
    {
        return toAjax(myUserService.insertMyUser(myUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('myuser:myuser:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyUser myUser)
    {
        return toAjax(myUserService.updateMyUser(myUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('myuser:myuser:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(myUserService.deleteMyUserByUserIds(userIds));
    }
}
